home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
8bit
/
cislib_a
/
getchr.doc
< prev
next >
Wrap
Text File
|
1995-04-22
|
3KB
|
72 lines
GETCHAR FOR VERSION 2
Just when you thought it was safe to go back to the compiler-
-IT has returned..."Char Wars II: The GetChar Strikes Back!"
A routine that waits for a single key to be pressed and
returns its value is one of the most popular programming
routines around. Back in the March/April issue of the
UPDATE...KYAN newsletter, a Pascal GetChar routine and an
assembly language GetChar procedure both appeared, and the
latter was somewhat more useful. The assembly language
GetChar procedure was written for use with Version 1.- of
Kyan Pascal and therefore will not work with Version 2.-.
For those of you who are having a hard time converting the
assembly language from Version 1.- to Version 2.-, I have
written a new GetChar function. It uses the CIOEqu.i
include file, available in this data library--see CIOEQU.DOC
and CIOEQU.PAS, for convenience. GetChar is called like
this:
Status := GetChar(Ch,Write_It);
Programming Techniques Used by GetChar
The first parameter passed to GetChar is a character variable
which will be changed to reflect the key that the user
presses. The second parameter is a boolean, and it instructs
GetChar whether or not to write the key that was pressed to
the screen (TRUE to write it, FALSE if you don't want the
character echoed to the screen).
Since GetChar uses CIO, I made it a function that will return
the CIO status byte (picked up from the Y register after a
JSR CIOV instruction). The English error message translation
of the status byte number can be found in Appendix D of the
Kyan Pascal manual. Just remember that a value of one (1)
indicates everything is all right--if it returns another
value something probably went wrong and you should inform the
user of the error and/or have your program try again.
The assembly code of GetChar first EQUates labels that are
for use with the stack pointer. By doing this, these equates
can easily be changed if the parameter list were to be
changed instead of having to go through the entire routine,
replacing stack pointer numbers.
It then goes on to temporarily store the Key variable in _t+1
and _t+2. Next, IOCB number one is closed and then opened,
so if it was open when GetChar was called, there could be
trouble. The compiler always uses the standard IOCB zero for
E: and IOCB6 for S:, so there should be no problem unless you
have a file open. The GetChar routine in the System
Utilities Toolkit contains a similar GetChar function that
takes care of this problem by finding a free IOCB.
Next, CIO is instructed to get one byte from the keyboard,
K:. If an error occurs during this read operation (or back
when the file was opened), GetChar will branch to the end,
close the IOCB, and return the error number. The byte that
was read is stored in the appropriate location using the
stack pointer, and then GetChar exits its assembly language
portion (notice how it jumped over the data bytes for the
device name--this is because if they are encountered as an
instruction, all sorts of fun things could happen during
runtime [for instance, my 130XE just plain locked up and shut
down before I figured out the problem and debugged it]).
(After downloading GETCHR.PAS, you should rename it to
GETCHAR.I on your disk.)